home *** CD-ROM | disk | FTP | other *** search
- Path: xanth!nic.MR.NET!hal!ncoast!allbery
- From: edf@ROCKY2.ROCKEFELLER.EDU (David MacKenzie)
- Newsgroups: comp.sources.misc
- Subject: v05i031: Interactive speller and other MicroEMACS macros
- Message-ID: <8811010650.AA24251@rocky2>
- Date: 2 Nov 88 02:23:49 GMT
- Sender: allbery@ncoast.UUCP
- Reply-To: edf@ROCKY2.ROCKEFELLER.EDU (David MacKenzie)
- Lines: 344
- Approved: allbery@ncoast.UUCP
-
- Posting-number: Volume 5, Issue 31
- Submitted-by: "David MacKenzie" <edf@ROCKY2.ROCKEFELLER.EDU>
- Archive-name: ue3.9-macros
-
- In light of the recent spate of spelling checkers, here is one that
- runs under MicroEMACS. Also, this summer there were discussions about
- automatically uncompressing files from GNU EMACS; this posting also
- contains macros to do that, as well as some other useful extensions.
- The speller depends on the Unix spell program; the other macros
- probably need Unix too. They have been tested under MicroEMACS3.9e.
-
- In the ^X! macro, note the line that prints "[End]" and wait for a
- keypress; MicroEMACS 3.9e apparently has a bug in that under some OS's,
- including Unix, shell-command always waits for a keystroke after
- running, while in others, such as MS-DOS, it only does so if it's not
- being run from a macro. Comment that line out if you haven't fixed
- that bug for Unix (it just involves adding an "if (clexec == FALSE)
- {...}" around the four lines of code in spawn.c that wait for the
- keypress).
-
- I have the contents of enhance.cmd in my .emacsrc; I load spell.cmd when
- I need it with M-x execute-file.
-
- David MacKenzie
-
- #! /bin/sh
- # This is a shell archive. Remove anything before this line, then unpack
- # it by saving it into a file and typing "sh file". To overwrite existing
- # files, type "sh file -c". You can also feed this as standard input via
- # unshar, or by typing "sh <file", e.g.. If this archive is complete, you
- # will see the following message at the end:
- # "End of shell archive."
- # Contents: enhance.cmd spell.cmd
- # Wrapped by dave@edfdc on Fri Sep 9 00:57:35 1988
- PATH=/bin:/usr/bin:/usr/ucb ; export PATH
- if test -f 'enhance.cmd' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'enhance.cmd'\"
- else
- echo shar: Extracting \"'enhance.cmd'\" \(4045 characters\)
- sed "s/^X//" >'enhance.cmd' <<'END_OF_FILE'
- X; enhance.cmd
- X;
- X; MicroEMACS 3.9 macros
- X;
- X; I. New bindings
- X; A. ESC-ESC -> execute command line
- X; B. ESC-^X -> execute current buffer
- X; C. ESC-TAB -> toggle OVERstrike mode
- X; D. ESC-# -> filter region through a program
- X; II. Enhancements to existing bindings
- X; B. ^X! allows response of "!" to repeat previous command
- X; C. ^X^F, ^X^V, ^X^R, ^X^I, ^X^W, ^X^N expand ~/file properly
- X; D. ^X^F, ^X^V, ^X^R, ^X^I check if the file exists only in
- X; compressed form (ending with ".Z"), and if so, uncompress it
- X;
- X; David MacKenzie
- X; Latest revision: 09/08/88
- X
- X
- X; Set up ESC-ESC to execute a macro language command from keyboard.
- Xbind-to-key execute-command-line M-^[
- X
- X; Set up ESC-Ctrl-X to execute the current buffer.
- X1 store-macro
- X execute-buffer $cbufname
- X!endm
- Xbind-to-key execute-macro-1 M-^x
- X
- X; Set up M-TAB to toggle insert/overstrike.
- X2 store-macro
- X set $cmode &bxor $cmode 32
- X!endm
- Xbind-to-key execute-macro-2 M-^I
- X
- X; Add !! (repeat previous command) capability to shell-command.
- X; Activated by a response of "!<Return>".
- Xset %prev-cmd "!"
- X3 store-macro
- X set %shell-cmd @"!"
- X !if &sequal %shell-cmd "ERROR" ; Ctrl-G hit.
- X !return
- X !endif
- X !if &sequal %shell-cmd "!"
- X !if &sequal %prev-cmd "!"
- X write-message "[No previous command]"
- X !return
- X !endif
- X ; Echo the command we're repeating for reference, a la csh.
- X write-message &cat "!" &cat %prev-cmd "~r~n"; CRLF
- X set %shell-cmd %prev-cmd
- X !else
- X set %prev-cmd %shell-cmd
- X !endif
- X shell-command %shell-cmd
- X write-message "[End]"
- X set %rckey >key
- X!endm
- Xbind-to-key execute-macro-3 ^X!
- X
- X; If %fname starts with "~/", substitute the value of HOME from environ.
- Xstore-procedure tildesub
- X ; ~ is MicroEMACS's escape character so we need to escape it.
- X !if &sequal &left %fname 2 "~~/"
- X set %fname &cat &env "HOME" &right %fname &sub &length %fname 1
- X !endif
- X!endm
- X
- X; If %fname exists only as a compressed file, uncompress it first.
- Xstore-procedure zcheck
- X !if &and ¬ &exi %fname &exi &cat %fname ".Z"
- X shell-command &cat "uncompress -v " %fname
- X !endif
- X!endm
- X
- X; Add tilde substitution on file finding, viewing, etc.
- X4 store-macro
- X set %fname @"Find file: "
- X !if &sequal %fname "ERROR" ; Ctrl-G hit.
- X !return
- X !endif
- X run tildesub
- X run zcheck
- X find-file %fname
- X!endm
- Xbind-to-key execute-macro-4 ^X^F
- X
- X5 store-macro
- X set %fname @"View file: "
- X !if &sequal %fname "ERROR"
- X !return
- X !endif
- X run tildesub
- X run zcheck
- X view-file %fname
- X!endm
- Xbind-to-key execute-macro-5 ^X^V
- X
- X6 store-macro
- X set %fname @"Read file: "
- X !if &sequal %fname "ERROR"
- X !return
- X !endif
- X run tildesub
- X run zcheck
- X read-file %fname
- X!endm
- Xbind-to-key execute-macro-6 ^X^R
- X
- X7 store-macro
- X set %fname @"Insert file: "
- X !if &sequal %fname "ERROR"
- X !return
- X !endif
- X run tildesub
- X run zcheck
- X insert-file %fname
- X!endm
- Xbind-to-key execute-macro-7 ^X^I
- X
- X8 store-macro
- X set %fname @"Write file: "
- X !if &sequal %fname "ERROR"
- X !return
- X !endif
- X run tildesub
- X write-file %fname
- X!endm
- Xbind-to-key execute-macro-8 ^X^W
- X
- X9 store-macro
- X set %fname @"Name: "
- X !if &sequal %fname "ERROR"
- X !return
- X !endif
- X run tildesub
- X change-file-name %fname
- X!endm
- Xbind-to-key execute-macro-9 ^XN
- X
- X; Filter the region through an external command.
- X10 store-macro
- X set %filt-cmd @"#"
- X !if &or %sequal %filt-cmd "ERROR" &sequal %filt-cmd ""
- X !return
- X !endif
- X write-message "[Filtering region]"
- X kill-region
- X 2 split-current-window
- X select-buffer "[temp]"
- X yank
- X end-of-file
- X delete-previous-character ; Remove unwanted extra newline.
- X unmark-buffer
- X
- X filter-buffer %filt-cmd
- X
- X beginning-of-file
- X set-mark
- X end-of-file
- X kill-region
- X unmark-buffer
- X delete-window
- X yank
- X delete-buffer "[temp]"
- X write-message "[Region filtered]"
- X!endm
- Xbind-to-key execute-macro-10 M-#
- END_OF_FILE
- if test 4045 -ne `wc -c <'enhance.cmd'`; then
- echo shar: \"'enhance.cmd'\" unpacked with wrong size!
- fi
- # end of 'enhance.cmd'
- fi
- if test -f 'spell.cmd' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'spell.cmd'\"
- else
- echo shar: Extracting \"'spell.cmd'\" \(3560 characters\)
- sed "s/^X//" >'spell.cmd' <<'END_OF_FILE'
- X; spell.cmd
- X;
- X; semi-interactive MicroEMACS 3.9 spelling checker
- X; Based on the Unix spell command.
- X; Activate with M-x run spell-buffer
- X;
- X; David MacKenzie
- X; Latest revision: 08/18/88
- X
- X
- X; These enclose misspelled words. Change them if you don't like them.
- Xset %lmark "<<"
- Xset %rmark ">>"
- X
- Xstore-procedure spell-buffer
- X
- X set %savecbuf $cbufname
- X !if &sequal $cfname "" ; No filename!
- X set $cfname $cbufname ; Make one.
- X !endif
- X set %file $cfname
- X save-file ; Make sure it's up to date.
- X update-screen
- X
- X set %lfile @"Local word list filename (<Return> = none)? "
- X !if &or &sequal %lfile "q" &sequal %lfile "ERROR" ; Ctrl-G
- X write-message "[Spelling correction aborted]"
- X !return
- X !endif
- X !if ¬ &sequal %lfile ""
- X set %lfile &cat &cat "+" %lfile " "
- X !endif
- X
- X write-message "[Identifying possible misspellings...]"
- X ; run the command with output to the buffer, "command"
- X pipe-command &cat &cat "spell " %lfile %file
- X
- X ; "command" is now the selected buffer
- X delete-window
- X select-buffer %savecbuf
- X
- X !while "TRUE"
- X set %word #command
- X !if &sequal %word "ERROR"
- X !break ; No more mis-spelled words.
- X !endif
- X
- X update-screen
- X write-message &cat "Fix `" &cat %word "' ([y]/n)? "
- X set %yn >key
- X !if &or &sequal %yn "q" &equal &ascii %yn 7 ; Ctrl-G
- X write-message "[Spelling correction aborted]"
- X !return
- X !endif
- X !if &or &sequal %yn "y" &sequal %yn " "
- X beginning-of-file
- X !while "TRUE"
- X write-message &cat &cat "[Searching for `" %word "'...]"
- X !force search-forward %word
- X !if &sequal $status "FALSE"
- X !break ; No more matches of this word found.
- X !endif
- X run mark-word
- X update-screen ; Let them see the marked word.
- X set %new-word @&cat &cat "Replace `" %word "' with (<Return> to keep)? "
- X
- X !if &or &sequal %new-word "q" &sequal %new-word "ERROR"
- X run unmark-word
- X write-message "[Spelling correction aborted]"
- X !return
- X !endif
- X !if &sequal %new-word "n" ; Go on to the next wrong word.
- X run unmark-word
- X !break
- X !endif
- X !if &sequal %new-word "p" ; Repeat previous correction.
- X set %new-word %old-new
- X !endif
- X !if &sequal %new-word ""
- X run unmark-word
- X !else
- X run replace-word
- X !endif
- X set %old-new %new-word
- X update-screen
- X !endwhile
- X !endif
- X !endwhile
- X write-message "[Spelling correction completed]"
- X!endm
- X
- X; Mark a word with %lmark and %rmark.
- X; Assumes point is at the end of the word when called;
- X; leaves point after %rmark.
- Xstore-procedure mark-word
- X insert-string %rmark
- X set-mark
- X previous-word
- X insert-string %lmark
- X!endm
- X
- X; Remove the mark.
- X; Assumes point is where mark-word left it, after %lmark.
- X; Leaves point after the word.
- Xstore-procedure unmark-word
- X &len %lmark delete-previous-character ; Nuke %lmark.
- X exchange-point-and-mark ; Move past %rmark.
- X &len %rmark delete-previous-character ; Nuke %rmark
- X!endm
- X
- X; Replace the marked word with %new-word.
- X; Called instead of unmark-word.
- X; Leaves point after the word.
- Xstore-procedure replace-word
- X &len %lmark delete-previous-character ; Nuke %lmark.
- X kill-region ; Nuke word and %rmark.
- X insert-string %new-word
- X!endm
- END_OF_FILE
- if test 3560 -ne `wc -c <'spell.cmd'`; then
- echo shar: \"'spell.cmd'\" unpacked with wrong size!
- fi
- # end of 'spell.cmd'
- fi
- echo shar: End of shell archive.
- exit 0
-